package com.yuxi.al.sqrt;

/**
 * Created by yuxi on 2017/8/20.
 */
public class Sqrt {
    public static void main(String[] args) {
        System.out.println(sqrtFunction(5.00));
    }

    private static double sqrtFunction(double x) {
        if (x < 0) {

            return Double.NaN;
        }
        double err = 1e-15;
        double t = x;
        while (Math.abs(t - x / t) > err * t) {
            t = (x / t + t) / 2.0;
        }
        return t;
    }
}
